home *** CD-ROM | disk | FTP | other *** search
-
- // Copyright (C) 2002 by Luigi Pino. All Rights Reserved.
-
- /***************************************************************************/
-
- #include "../library/neurosis.h"
- #include "draw.h"
- #include "file_io.h"
- #include "hiscore.h"
- #include "initialize.h"
- #include "main.h"
- #include "menu_misc.h"
- #include "paddle.h"
- #include "sphere.h"
- #include "update.h"
-
- /***************************************************************************/
-
- extern bool connected[];
-
- extern High_Score_Struct high_score_sphere;
- extern High_Score_Struct high_score_time;
- extern Values_Struct values;
- extern Sub_Menu_Class menu_options;
- extern Sub_Menu_Class menu_control;
- extern Window_Class window;
- extern char high_score_name[];
-
- /***************************************************************************/
-
- void Load_Config_File()
-
- {
- FILE *stream;
- int x1;
- int next_char;
- int controller_value;
-
- if ((stream = fopen("config.ini", "r")) == NULL)
- {
- // Options
- menu_options.Set_Current_Choice(0, 0); // Sound = On
- menu_options.Set_Current_Choice(1, 0); // Resolution = 640 x 480
- window.screen_height = 480;
- window.screen_width = 640;
- menu_options.Set_Current_Choice(2, 0); // Timed amount = 5
- menu_options.Set_Current_Choice(3, 0); // Countdown amount = 300
- strncpy(high_score_name, "LP23", 15);
-
- // Controls
- menu_control.Set_Current_Choice(Up, Computer);
- menu_control.Set_Current_Choice(Down, Keyboard_1);
- menu_control.Set_Current_Choice(Left, Computer);
- menu_control.Set_Current_Choice(Right, Computer);
- menu_control.Set_Current_Choice(Compete, Keyboard_1);
-
- // High scores
- strncpy(high_score_sphere.name[0], "---------", 15);
- strncpy(high_score_sphere.name[1], "---------", 15);
- strncpy(high_score_sphere.name[2], "---------", 15);
- strncpy(high_score_sphere.name[3], "---------", 15);
- strncpy(high_score_sphere.name[4], "---------", 15);
-
- strncpy(high_score_time.name[0], "---------", 15);
- strncpy(high_score_time.name[1], "---------", 15);
- strncpy(high_score_time.name[2], "---------", 15);
- strncpy(high_score_time.name[3], "---------", 15);
- strncpy(high_score_time.name[4], "---------", 15);
-
- high_score_sphere.spheres[0] = high_score_time.spheres[0] = 30;
- high_score_sphere.spheres[1] = high_score_time.spheres[1] = 35;
- high_score_sphere.spheres[2] = high_score_time.spheres[2] = 40;
- high_score_sphere.spheres[3] = high_score_time.spheres[3] = 45;
- high_score_sphere.spheres[4] = high_score_time.spheres[4] = 50;
-
- high_score_sphere.time[0] = high_score_time.time[0] = 5.0f;
- high_score_sphere.time[1] = high_score_time.time[1] = 4.0f;
- high_score_sphere.time[2] = high_score_time.time[2] = 3.0f;
- high_score_sphere.time[3] = high_score_time.time[3] = 2.0f;
- high_score_sphere.time[4] = high_score_time.time[4] = 1.0f;
- }
- else
- {
- // Get sound value
- next_char = fgetc(stream);
-
- while (next_char != '=')
- next_char = fgetc(stream);
-
- fgetc(stream);
- next_char = fgetc(stream);
-
- if (next_char == 48)
- menu_options.Set_Current_Choice(0, 0); // Sound = On
- else
- menu_options.Set_Current_Choice(0, 1); // Sound = Off
-
- // Get resolution
- next_char = fgetc(stream);
-
- while (next_char != '=')
- next_char = fgetc(stream);
-
- fgetc(stream);
- next_char = fgetc(stream);
-
- if (next_char == 48)
- {
- window.screen_height = 480;
- window.screen_width = 640;
- menu_options.Set_Current_Choice(1, 0);
- }
- else if (next_char == 49)
- {
- window.screen_height = 600;
- window.screen_width = 800;
- menu_options.Set_Current_Choice(1, 1);
- }
- else
- {
- window.screen_height = 768;
- window.screen_width = 1024;
- menu_options.Set_Current_Choice(1, 2);
- }
-
- // Get timed value
- next_char = fgetc(stream);
-
- while (next_char != '=')
- next_char = fgetc(stream);
-
- fgetc(stream);
- next_char = fgetc(stream);
-
- if (next_char == 48)
- menu_options.Set_Current_Choice(2, 0); // Timed amount = 5;
- else if (next_char == 49)
- menu_options.Set_Current_Choice(2, 1); // Timed amount = 10;
- else
- menu_options.Set_Current_Choice(2, 2); // Timed amount = 15;
-
- // Get countdown value
- next_char = fgetc(stream);
-
- while (next_char != '=')
- next_char = fgetc(stream);
-
- fgetc(stream);
- next_char = fgetc(stream);
-
- if (next_char == 48)
- menu_options.Set_Current_Choice(3, 0); // Countdown amount = 300
- else if (next_char == 49)
- menu_options.Set_Current_Choice(3, 1); // Countdown amount = 600
- else
- menu_options.Set_Current_Choice(3, 2); // Countdown amount = 900
-
- // Get name
- next_char = fgetc(stream);
-
- while (next_char != '=')
- next_char = fgetc(stream);
-
- fgetc(stream);
- fscanf(stream, "%15s", high_score_name);
-
- // Get top control
- next_char = fgetc(stream);
-
- while (next_char != '=')
- next_char = fgetc(stream);
-
- fgetc(stream);
- next_char = fgetc(stream);
-
- controller_value = next_char - 48;
-
- if ((controller_value < Keyboard_1) || (controller_value > No_User))
- menu_control.Set_Current_Choice(Up, Computer);
- else
- {
- if (connected[controller_value] == false)
- menu_control.Set_Current_Choice(Up, Computer);
- else
- menu_control.Set_Current_Choice(Up, controller_value);
- }
-
- // Get bottom control
- next_char = fgetc(stream);
-
- while (next_char != '=')
- next_char = fgetc(stream);
-
- fgetc(stream);
- next_char = fgetc(stream);
-
- controller_value = next_char - 48;
-
- if ((controller_value < Keyboard_1) || (controller_value > No_User))
- menu_control.Set_Current_Choice(Down, Computer);
- else
- {
- if (connected[controller_value] == false)
- menu_control.Set_Current_Choice(Down, Computer);
- else
- menu_control.Set_Current_Choice(Down, controller_value);
- }
-
- // Get left control
- next_char = fgetc(stream);
-
- while (next_char != '=')
- next_char = fgetc(stream);
-
- fgetc(stream);
- next_char = fgetc(stream);
-
- controller_value = next_char - 48;
-
- if ((controller_value < Keyboard_1) || (controller_value > No_User))
- menu_control.Set_Current_Choice(Left, Computer);
- else
- {
- if (connected[controller_value] == false)
- menu_control.Set_Current_Choice(Left, Computer);
- else
- menu_control.Set_Current_Choice(Left, controller_value);
- }
-
- // Get right control
- next_char = fgetc(stream);
-
- while (next_char != '=')
- next_char = fgetc(stream);
-
- fgetc(stream);
- next_char = fgetc(stream);
-
- controller_value = next_char - 48;
-
- if ((controller_value < Keyboard_1) || (controller_value > No_User))
- menu_control.Set_Current_Choice(Right, Computer);
- else
- {
- if (connected[controller_value] == false)
- menu_control.Set_Current_Choice(Right, Computer);
- else
- menu_control.Set_Current_Choice(Right, controller_value);
- }
-
- // Get compete control
- next_char = fgetc(stream);
-
- while (next_char != '=')
- next_char = fgetc(stream);
-
- fgetc(stream);
- next_char = fgetc(stream);
-
- controller_value = next_char - 48;
-
- if ((controller_value < Keyboard_1) || (controller_value > Joystick_4))
- menu_control.Set_Current_Choice(Compete, Computer);
- else
- {
- if (connected[controller_value] == false)
- menu_control.Set_Current_Choice(Compete, Keyboard_1);
- else
- menu_control.Set_Current_Choice(Compete, controller_value);
- }
-
- // Get high scores by spheres
- for (x1=0;x1<5;x1=x1+1)
- {
- next_char = fgetc(stream);
- while (next_char != '=')
- next_char = fgetc(stream);
-
- fgetc(stream);
- fscanf(stream, "%15s", high_score_sphere.name[x1]);
-
- next_char = fgetc(stream);
- while (next_char != '=')
- next_char = fgetc(stream);
-
- fgetc(stream);
- fscanf(stream, "%i", &high_score_sphere.spheres[x1]);
-
- next_char = fgetc(stream);
- while (next_char != '=')
- next_char = fgetc(stream);
-
- fgetc(stream);
- fscanf(stream, "%f", &high_score_sphere.time[x1]);
- }
-
- // Get high scores by time
- for (x1=0;x1<5;x1=x1+1)
- {
- next_char = fgetc(stream);
- while (next_char != '=')
- next_char = fgetc(stream);
-
- fgetc(stream);
- fscanf(stream, "%15s", high_score_time.name[x1]);
-
- next_char = fgetc(stream);
- while (next_char != '=')
- next_char = fgetc(stream);
-
- fgetc(stream);
- fscanf(stream, "%i", &high_score_time.spheres[x1]);
-
- next_char = fgetc(stream);
- while (next_char != '=')
- next_char = fgetc(stream);
-
- fgetc(stream);
- fscanf(stream, "%f", &high_score_time.time[x1]);
- }
-
- fclose(stream);
- }
-
- // Count players
- values.player_number = 0;
-
- for (x1=Up;x1<=Right;x1=x1+1)
- {
- if (menu_control.Get_Current_Choice(x1) != No_User)
- values.player_number = values.player_number + 1;
- }
-
- // Adjust if less than 2 players (add computer)
- if (values.player_number <= 1)
- {
- menu_control.Set_Current_Choice(Up, Computer);
- menu_control.Set_Current_Choice(Down, Computer);
- }
- }
-
- /***************************************************************************/
-
- void Save_Config_File()
-
- {
- FILE *stream;
- int x1;
-
- stream = fopen("config.ini", "w");
-
- fprintf(stream, "-----------------------------------------------------------------\n\n");
- fprintf(stream, "Sound (ON, OFF) = %i\n", menu_options.Get_Current_Choice(0));
- fprintf(stream, "Resolution (640, 800, 1024) = %i\n", menu_options.Get_Current_Choice(1));
- fprintf(stream, "Timed (5, 10, 15) = %i\n", menu_options.Get_Current_Choice(2));
- fprintf(stream, "Countdown (300, 600, 900) = %i\n", menu_options.Get_Current_Choice(3));
- fprintf(stream, "Name = %s\n", high_score_name);
- fprintf(stream, "Top = %i\n", menu_control.Get_Current_Choice(Up));
- fprintf(stream, "Bottom = %i\n", menu_control.Get_Current_Choice(Down));
- fprintf(stream, "Left = %i\n", menu_control.Get_Current_Choice(Left));
- fprintf(stream, "Right = %i\n", menu_control.Get_Current_Choice(Right));
- fprintf(stream, "Compete = %i\n\n", menu_control.Get_Current_Choice(Compete));
- fprintf(stream, "-----------------------------------------------------------------\n\n");
-
- for (x1=0;x1<5;x1=x1+1)
- {
- fprintf(stream, "Hiscore %i", x1 + 1);
- fprintf(stream, "a = %s = %i = %.2f\n", high_score_sphere.name[x1], high_score_sphere.spheres[x1], high_score_sphere.time[x1]);
- }
-
- fprintf(stream, "\n");
-
- for (x1=0;x1<5;x1=x1+1)
- {
- fprintf(stream, "Hiscore %i", x1 + 1);
- fprintf(stream, "b = %s = %i = %.2f\n", high_score_time.name[x1], high_score_time.spheres[x1], high_score_time.time[x1]);
- }
-
- fprintf(stream, "\n");
- fprintf(stream, "-----------------------------------------------------------------\n");
- fclose(stream);
- }
-
- /***************************************************************************/